<?php
$host = 'localhost';  // MySQL主机
$dbname = 'test_db';  // 数据库名
$sql_user = 'hwq';  // 用户名
$sql_passwd = 'hwq1123';  // 密码
$conn = mysqli_connect($host, $sql_user, $sql_passwd);
if(! $conn )
{
    die('连接失败: ' . mysqli_error($conn));
}
echo '连接成功\n';
$sql = "CREATE TABLE electricity_grid_power( ".
        "ser_in_day int not null default 0, ".
        "current_phase_A float not null default 0, ".
        "current_phase_B float not null default 0, ".
        "current_phase_C float not null default 0, ".
        "active_power float not null default 0,".
        "reactive_power float not null default 0,".  
        "PRIMARY KEY ( ser_in_day )); ";

$sql2 = "CREATE TABLE electricity_grid_energy( ".
        "date DATE not null, ". 
        "active_energy_in_day float not null default 0,".
        "reactive_energy_in_day float not null default 0,".
        "energy_of_peak_in_day float not null default 0,".
        "energy_of_high_in_day float not null default 0,".
        "energy_of_normal_in_day float not null default 0,".
        "energy_of_low_in_day float not null default 0,".        
        "PRIMARY KEY ( date )); ";
mysqli_select_db( $conn, $dbname );
$retval = mysqli_query( $conn, $sql );
if(! $retval )
{
    die('数据表 electricity_grid_power 创建失败: ' . mysqli_error($conn));
}
echo "数据表 electricity_grid_power 创建成功\n";
$retval = mysqli_query( $conn, $sql2 );
if(! $retval )
{
    die('数据表 electricity_grid_energy 创建失败: ' . mysqli_error($conn));
}
echo "数据表 electricity_grid_energy 创建成功\n";
mysqli_close($conn);
?>